package com.wanshi.entity;

import com.wanshi.utils.StringUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

public class User implements Serializable {

    public static void main(String[] args) {
        String zhengze = "^[a-zA-Z0-9_]{6,20}$";

        System.out.println("zhang123".matches(zhengze));
    }

    private int id;
    private String username;
    private String password;
    private String gender;
    private String hobby ;
    private  String city ;
    private String introduce ;

    public String getPicurl() {
        return picurl;
    }

    public void setPicurl(String picurl) {
        this.picurl = picurl;
    }

    private String picurl;
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getHobby() {
        return hobby;
    }

    public void setHobby(String hobby) {
        this.hobby = hobby;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getIntroduce() {
        return introduce;
    }

    public void setIntroduce(String introduce) {
        this.introduce = introduce;
    }

    public User(String username, String password, String gender, String hobby, String city, String introduce) {
        this.username = username;
        this.password = password;
        this.gender = gender;
        this.hobby = hobby;
        this.city = city;
        this.introduce = introduce;
    }

    public User() {
    }

    @Override
    public String toString() {
        return "User{" +
                "id=" + id +
                ", username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", gender='" + gender + '\'' +
                ", hobby='" + hobby + '\'' +
                ", city='" + city + '\'' +
                ", introduce='" + introduce + '\'' +
                ", picurl='" + picurl + '\'' +
                '}';
    }

    //Map<String,String>  键是 input的name属性值, 值错误提示
    public Map<String,String> checkUser(){
        Map<String,String> errorMap = new HashMap<>();
        String zhengze = "^[a-zA-Z0-9_]{6,20}$";
        if (StringUtils.isEmpty(username)){
            errorMap.put("username","用户名不能为空");
        }else if(!username.matches(zhengze)){
            errorMap.put("username","用户名不满足格式");
        }


        if(StringUtils.isEmpty(password)){
            errorMap.put("password","密码不能为空");
        }
        if(StringUtils.isEmpty(gender)){
            errorMap.put("gender","性别不能为空");
        }
        if(StringUtils.isEmpty(hobby)){
            errorMap.put("hobby","爱好不能为空");
        }
        if(StringUtils.isEmpty(city)){
            errorMap.put("city","城市不能为空");
        }
        if(StringUtils.isEmpty(introduce)){
            errorMap.put("introduce","自我介绍不能为空");
        }
        if(StringUtils.isEmpty(picurl)){
            errorMap.put("picurl","照片不能为空");
        }

        return errorMap;

    }
}
